package com.zhengtoudai.ui.presenter;

import android.app.Activity;

import com.zhengtoudai.http.HttpApi;
import com.zhengtoudai.injector.PerActivity;
import com.zhengtoudai.ui.bean.Index;
import com.zhengtoudai.ui.bean.Result;
import com.zhengtoudai.ui.view.IndexView;

import javax.inject.Inject;

import rx.Observer;
import rx.functions.Action0;

/**
 * Created by Administrator on 2016/9/1 0001.
 */
@PerActivity
public class IndexPresenterImpl extends BasePresenterImpl<IndexView> implements IndexPresenter {
    private Activity mActivity;

    @Inject
    public IndexPresenterImpl(Activity activity) {
        mActivity = activity;
    }

    @Override
    public void getIndexBorrow() {
        mSubscription = HttpApi.getInstance().getIndexBorrow().doOnSubscribe(new Action0() {
            @Override
            public void call() {
                mView.showIndexDialog();
            }
        }).subscribe(new Observer<Result<Index>>() {
            @Override
            public void onCompleted() {
                mView.dismissIndexDialog();
            }

            @Override
            public void onError(Throwable e) {
                mView.onIndexFailure(e);
                mView.dismissIndexDialog();
            }

            @Override
            public void onNext(Result<Index> result) {
                mView.onIndexResult(result.getResult());
            }
        });
    }
}
